const http = require('../../utils/http')

Page({
      data: {
            myAccount: {}
      },
      onLoad: function (options) {
            this.getMyAccount();
      },
      getMyAccount() {
            wx.showLoading();
            http.request({
                      url: '/wallet/myWallet',
                      method: 'GET',
                      callBack: (res) => {
                            if (res.code == 200) {
                                  let data = res.data;
                                  data.balanceAccount = parseFloat(res.data.balanceAccount / 100).toFixed(2)
                                  data.totalAccount = parseFloat(res.data.totalAccount / 100).toFixed(2)
                                  data.trainerAccount = parseFloat(res.data.trainerAccount / 100).toFixed(2)
                                  data.trainerCanWithdraw = parseFloat(res.data.trainerCanWithdraw / 100).toFixed(2)


                                  this.setData({
                                        myAccount: data
                                  })
                            } else {
                                  wx.showToast({
                                        title: res.msg,
                                        icon: 'none'
                                  })
                            }
                            wx.hideLoading();
                      }
                }
            )
      },
      ToDetailPage(e) {
            let type = e.currentTarget.dataset.type;
            let detail = e.currentTarget.dataset.page

            let price = type == 1 ? this.data.myAccount.balanceAccount : this.data.myAccount.trainerAccount
            wx.navigateTo({
                  url: './account-detail/index?type=' + type + '&price=' + price,
                  success(res) {

                  }
            })

      },
      toWithDraw(e) {

            let detail = e.currentTarget.dataset.page
            console.log(detail, 'detail---')
            let type = e.currentTarget.dataset.type;
            let price = type == 2 ? this.data.myAccount.balanceAccount : this.data.myAccount.trainerCanWithdraw
            wx.navigateTo({
                  url: '/pages/withDraw/index?price=' + price + '&type=' + type,
                  success(res) {

                  }
            })

      },
      submitFormData() {
            wx.navigateTo({
                  url: '/pages/bankList/index'
            })
      }
});